//
//  CampusSchoolItemModel.m
//  ShowYork
//
//  Created by hxh on 2021/3/30.
//  Copyright © 2021 hxh. All rights reserved.
//

#import "CampusSchoolItemModel.h"
#import "CampusConfigModel.h"
#import "CampusParamItemModel.h"
@implementation CampusSchoolItemModel
- (NSArray *)hierarchyArray{
 
    

    NSArray *result = [self.hierarchy componentsSeparatedByString:@","];
    
    NSMutableArray *dataArray = [NSMutableArray array];
    
    CampusConfigModel *model = [CampusConfigModel getWithKey:@"hierarchy"];
    
    [model.paramList enumerateObjectsUsingBlock:^(CampusParamItemModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [result enumerateObjectsUsingBlock:^(NSString * _Nonnull value, NSUInteger idx, BOOL * _Nonnull stop) {
            if ([value isEqualToString:obj.name]) {
                [dataArray addObject:obj.value];
            }
        }];
    }];
    return dataArray;
}



- (CGFloat)itemH{
    
    CGFloat maxWidth = kScreenW - 140;
    
    CGFloat margin = 8.0f;

    CGFloat itemHeight = 16;
    
    CGFloat totalWidth = 0;
    
    CGFloat totalHeight = 32.0f;
    
    for (NSString * string in self.hierarchyArray) {
        CGSize size = [RPAppManager getTextSizeWithText:string font:font(10) maxSize:CGSizeMake(kScreenW, MAXFLOAT)];
        if (ceil(size.width) + 10 + margin + totalWidth > maxWidth) {
            totalHeight = itemHeight + margin + totalHeight;
            totalWidth = 0;
        }else{
            totalWidth = totalWidth + ceil(size.width) + 10 + margin;
        }
    }
    return totalHeight;
}
@end
